'''
Created on Jul 19, 2013

@author: a.renduchintala
'''

import numpy as np
from GMM import GMM
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab


b1 = np.random.multivariate_normal([2, 10], [[2, 5], [5, 7]], 100) 
b2 = np.random.multivariate_normal([20, 30], [[8, 9], [9, 6]], 100) 
b3 = np.random.multivariate_normal([36, 0], [[13.5, -10], [-10, 4]], 100) 
X = np.matrix(np.vstack((b1, b2, b3)))
gmm = GMM(3)
gmm.fit(X)


fig = plt.figure()

x = np.arange(np.min(X), np.max(X), 0.1)
y = np.arange(np.min(X), np.max(X), 0.1)
Xc, Yc = np.meshgrid(x, y)
plt.axis([np.min(X), np.max(X), np.min(X), np.max(X)])
ax = plt.gca()
ax.set_autoscale_on(False)
# difference of Gaussians



for i in range(gmm.K):
    (wt, mu, sigma) = gmm.model_estimates[i]
    mu = np.asarray(mu).tolist()[0]
    sigma = sigma.tolist()
    print 'gaussian', i, '\n', 'mean:', mu, '\nvariance:', sigma, '\nweight:', wt
    Zc = mlab.bivariate_normal(Xc, Yc, sigmax=sigma[0][0], sigmay=sigma[1][1], mux=mu[0], muy=mu[1], sigmaxy=sigma[0][1])
    plt.contour(Xc, Yc, Zc)

plt.scatter(np.array(X[:, 0]).flatten().tolist(), np.array(X[:, 1]).flatten().tolist());
plt.savefig("tmp.png")
